//
//  controllerFlowVC.swift
//  swiftDemo
//
//  Created by yaqiang bi on 2017/3/10.
//  Copyright © 2017年 毕小强. All rights reserved.
//

/**
 *
 * ......................我佛慈悲......................
 *                       _oo0oo_
 *                      o8888888o
 *                      88" . "88
 *                      (| -_- |)
 *                      0\  =  /0
 *                    ___/`---'\___
 *                  .' \\|     |// '.
 *                 / \\|||  :  |||// \
 *                / _||||| -卍-|||||- \
 *               |   | \\\  -  /// |   |
 *               | \_|  ''\---/''  |_/ |
 *               \  .-\__  '-'  ___/-. /
 *             ___'. .'  /--.--\  `. .'___
 *          ."" '<  `.___\_<|>_/___.' >' "".
 *         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *         \  \ `_.   \_ __\ /__ _/   .-` /  /
 *     =====`-.____`.___ \_____/___.-`___.-'=====
 *                       `=---='
 *
 *..................佛祖开光 ,永无BUG...................
 *
 */

import UIKit

class controllerFlowVC: UIViewController {
    public var mutableDic :[Int:String] = [:]
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
       /**
         * for in 循环
         *
         */
        for index in 0...5 {
            print(index)
        }
        
        /**
         *  while循环
         */
        let finalSquare = 25
        var square = 0
        var dicRoll = 0
        var board = Array(repeating: 0, count: finalSquare+1)
        board[03] = +08; board[06] = +11; board[09] = +09; board[10] = +02
        board[14] = -10; board[19] = -11; board[22] = -02; board[24] = -08
        while square<finalSquare {
            dicRoll += 1
            if dicRoll == 7 {
                dicRoll = 1
            }
            square += dicRoll
            if square < board.count {
                square += board[square]
            }
        }
        print("Game over")
        
        
        square = 0
        dicRoll = 0
        repeat{
            dicRoll += 1
            if dicRoll == 7 {
                dicRoll = 1
            }
            square += dicRoll
            if square < board.count {
                square += board[square]
            }
            
        }while square<finalSquare
        print("Game over again")
        
        /**
         *   switch
         */
        let character : Character = "a"
        switch character {
        case "A","a":
            print("This is a")
        case "b":
            print("This is b")
        default:
            print("noting")
        }
        
        let count = 62
        switch count {
        case 0...10:
            print("count is 0...10")
        case 11...20:
            print("count is 11...20")
        case 21...100:
            print("count is 21...100")
        default:
            print("beyond")
        }
        
        let point = (1,1)
        switch point {
        case (0,0):
            print("point is origin")
        case (_,0):
            print("point is on the X")
        case (0,_):
            print("point is on the Y")
        case (-2...2,-2...2):
            print("point is in the box")
        default:
            print("point is outside")
        }
        
        let anotherPoint = (2,0)
        switch anotherPoint {
        case (let x,0):
            print("point is on the X \(x)")
        case (0,let y):
            print("point is on the Y \(y)")
        case let(x,y):
            print("point else \(x) \(y)")
        }
        
        /*
         *      where
         **/
        let yetAnotherPoint = (1,-1)
        switch yetAnotherPoint {
        case let (x,y) where x == y:
            print("(\(x,y))is on the line x==y")
        case let (x,y) where x == -y:
            print("(\(x,y))is on the line x==-y")
        case let (x,y):
             print("(\(x), \(y)) is just some arbitrary point")
        }
        
        
        /**
         * continue 停止当前循环再次从头开始循环的下一次遍历
         */
        let puzzleInput = "greate minds think alike"
        var puzzleOutput = ""
        for character in puzzleInput.characters {
            switch character {
            case "a","e","i","o","u"," ":
                continue
            default:
                puzzleOutput.append(character)
            }
        }
        print(puzzleOutput)
        
        let lab = UILabel(frame: CGRect(x: 10, y: 74, width: 100, height: 30))
        lab.textColor = UIColor.red
        lab.font = UIFont.systemFont(ofSize: 14)
        lab.text = puzzleOutput
        self.view.addSubview(lab)
        
        for charater in 0...10 {
            if charater == 5{
                continue
            }
            print(charater)
        }
        
        /*
         *  break会立即结束循环
         **/
        let numberSymbol: Character = "三"  // Simplified Chinese for the number 3
        var possibleIntegerValue: Int?
        switch numberSymbol {
        case "1", "١", "一", "๑":
            possibleIntegerValue = 1
        case "2", "٢", "二", "๒":
            possibleIntegerValue = 2
        case "3", "٣", "三", "๓":
            possibleIntegerValue = 3
        case "4", "٤", "四", "๔":
            possibleIntegerValue = 4
        default:
            break
        }
        if let integerValue = possibleIntegerValue {
            print("The integer value of \(numberSymbol) is \(integerValue).")
        } else {
            print("An integer value could not be found for \(numberSymbol).")
        }
        
        for charater in 0...10 {
            if charater == 5{
               break
            }
            print(charater)
        }
        
        /*
         *    fallthrough
         **/
        let integerValue = 5
        var description :String = ""
        switch integerValue {
        case 0...5:
            description += "\(integerValue)"
            fallthrough
        default:
            description += " is empty"
        }
        print(description)
        
        /*
         *    给语句打标签
         **/
        let finalCount = 25
        var countArr = [Int](repeating: 0,count:finalCount+1)
        countArr[03] = +08; countArr[06] = +11; countArr[09] = +09; countArr[10] = +02
        countArr[14] = -10; countArr[19] = -11; countArr[22] = -02; countArr[24] = -08
        var Roll = 0
        var go = 0
        gameLoop:while go != finalCount {
            Roll += 1
            if Roll == 7 {
                Roll = 1
            }
            switch go+Roll {
            case finalCount:
                go += Roll
                break gameLoop
            case let newSquare where newSquare>finalCount:
                continue gameLoop
            default:
                go += Roll
                go += countArr[go]
            }
        }
        print("刚好走到了终点\(go)")
        
        /*
         *    guard控制
         **/
        self.greet(person: ["name":"Jack","location":"beijing"])
        
        /**
         *      API可用性
         */
        if #available(iOS 10,macOS 10.12, *) {
            print("Use iOS 10 APIs on iOS, and use macOS 10.12 APIs on macOS")
        }else{
            print("Fall back to earlier iOS and macOS APIs")
        }
    }
    
    /// guard 控制函数
    ///
    /// - Parameter person: 个人信息
    func greet(person:[String:String])  {
        guard let name = person["name"] else {
            return
        }
        print("Hello \(name)")
        
        guard let location = person["location"] else {
            print("I hope the weather is nice near you.")
            return
        }
        print("I hope the weather is nice in \(location)")
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
